<?php
header('Content-Type: application/json;charset=utf-8');
header('Access-Control-Allow-Origin: *'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: false'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin,authorization'); // 设置允许自定义请求头的字段

date_default_timezone_set("Asia/Shanghai");

function getDateTime()
{
    return date('Y-m-d H:i:s');
}

$host = '127.0.0.1';
$user = 'root';
$password = 'yx110120';
$dbName = 'system';

$connect = mysqli_connect($host, $user, $password, $dbName);

date_default_timezone_set('PRC');

function checkLogin()
{  
    $result = getallheaders();
    $token = "";
    foreach ($result as $key => $value) {
        if($key === "Authorization"){
            $token = getallheaders()["Authorization"];
        } else if($key === "authorization"){
            $token = getallheaders()["authorization"];
        }
    }
    session_id("admin");
    session_start();
    if (empty($_SESSION['admin']) || $token != $_SESSION['admin'] ) {
        die(json_encode(array("code" => 1010, "msg" => "未登录", "data" => null)));
    }
}
// checkLogin();